<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试注册功能</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
            max-width: 800px;
            margin: 0 auto;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, textarea {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        button {
            padding: 10px 15px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        pre {
            background-color: #f5f5f5;
            padding: 15px;
            overflow: auto;
        }
    </style>
</head>
<body>
    <h1>测试注册功能</h1>
    
    <div class="form-group">
        <label for="username">用户名</label>
        <input type="text" id="username" value="testuser">
    </div>
    
    <div class="form-group">
        <label for="password">密码</label>
        <input type="password" id="password" value="password123">
    </div>
    
    <div class="form-group">
        <label for="realName">真实姓名</label>
        <input type="text" id="realName" value="测试用户">
    </div>
    
    <div class="form-group">
        <label for="email">电子邮箱</label>
        <input type="email" id="email" value="test@example.com">
    </div>
    
    <div class="form-group">
        <label for="phone">手机号码</label>
        <input type="text" id="phone" value="13800138000">
    </div>
    
    <div class="form-group">
        <label for="role">角色 (1-管理员，2-项目经理，3-团队成员)</label>
        <input type="number" id="role" min="1" max="3" value="3">
    </div>
    
    <button onclick="testRegister()">测试注册</button>
    
    <h2>注册请求数据</h2>
    <pre id="requestData"></pre>
    
    <h2>响应结果</h2>
    <pre id="responseData"></pre>
    
    <script>
        function testRegister() {
            // 收集表单数据
            const userData = {
                username: document.getElementById('username').value,
                password: document.getElementById('password').value,
                realName: document.getElementById('realName').value,
                email: document.getElementById('email').value,
                phone: document.getElementById('phone').value,
                role: parseInt(document.getElementById('role').value)
            };
            
            // 显示请求数据
            document.getElementById('requestData').textContent = JSON.stringify(userData, null, 2);
            
            // 发送请求
            fetch('/risk-management/register', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(userData)
            })
            .then(response => {
                // 检查HTTP状态
                if (!response.ok) {
                    if (response.status === 403) {
                        throw new Error('权限错误 (403 Forbidden): CSRF保护可能阻止了请求，请尝试刷新页面');
                    }
                    throw new Error('服务器错误: ' + response.status);
                }
                return response.json();
            })
            .then(data => {
                // 显示响应数据
                document.getElementById('responseData').textContent = JSON.stringify(data, null, 2);
            })
            .catch(error => {
                document.getElementById('responseData').textContent = '请求出错: ' + error.message;
                console.error('注册请求出错:', error);
            });
        }
    </script>
</body>
</html> 